﻿using System;
using System.Collections.Generic;
using System.Web;
using EcsSiteDSTableAdapters;
using System.ComponentModel;


namespace SiteECSWeb
{
    [DataObject]
    public class DeprtCategoryBLL
    {
        private DepCategoryTableAdapter _DepCategoryTableAdapter = null;

        protected DepCategoryTableAdapter DepCategoryTableAdapter
        {
            get
            {
                if (_DepCategoryTableAdapter == null)
                {
                    _DepCategoryTableAdapter = new DepCategoryTableAdapter();
                }
                return _DepCategoryTableAdapter;
            }
        }

        #region SelectDeptCategory
      
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.DepCategoryDataTable GetDepartmentCategoryRowRank()
        {
            return DepCategoryTableAdapter.GetDepCategoryRowRankData();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryGrandFather()
        {
            return DepCategoryTableAdapter.GetDepCategoryGrandFatherData();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryByRowRank(int RowRank)
        {
            return DepCategoryTableAdapter.GetDepCategoryDataByRowRank(RowRank);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryByDepCatID(int DepCatID)
        {
            return DepCategoryTableAdapter.GetDepCategoryDataByDepCatID(DepCatID);
        }
        
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryMainDepManager()
        {
            return DepCategoryTableAdapter.GetDepCategoryMainDepManagerData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryECSDep()
        {
            return DepCategoryTableAdapter.GetDepCategoryECSDepData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryByDepName(string DepCat_NameEn)
        {
            return DepCategoryTableAdapter.GetDepCategoryDataByDepName(DepCat_NameEn);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.DepCategoryDataTable GetDepCategoryByEmail(string DepCat_Email)
        {
            return DepCategoryTableAdapter.GetDepCategoryDataByEmail(DepCat_Email);
        }

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.DepCategoryDataTable GetEcsFatherDept()
        //{
        //    return DepCategoryTableAdapter.GetDepCategoryDataFatherDept();
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.DepCategoryDataTable GetEcsSonDept()
        //{
        //    return DepCategoryTableAdapter.GetDepCategoryDataDepSon();
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.DepCategoryDataTable GetEcsNephewDept()
        //{
        //    return DepCategoryTableAdapter.GetDepCategoryDataDepNephew();
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.DepCategoryDataTable GetEcsFatherDeptByGrandId(int EcsGrandId)
        //{
        //    return DepCategoryTableAdapter.GetDepFatherDataByDepGrand(EcsGrandId);
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.DepCategoryDataTable GetEcsSonDeptByFatherId(int EcsfFatherId)
        //{
        //    return DepCategoryTableAdapter.GetDepCategoryDepSonDataByDepFather(EcsfFatherId);
        //}
        #endregion


        #region InsertDepartment
        // insert All Column into EcsOffice Table//
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public bool AddDepartment
            (string DepCat_NameAr, string DepCat_NameEn, int? DepCat_DeptCategID, int? DepCat_DeptID, int? DepCat_SubDeptID,
            string DepCat_MangerPhone, string DepCat_MangerInternalPhone, string DepCat_Phone, string DepCat_InternalPhone,
            string DepCat_Email)
        {

            EcsSiteDS.DepCategoryDataTable DepTable = new EcsSiteDS.DepCategoryDataTable();
            EcsSiteDS.DepCategoryRow DepRow = DepTable.NewDepCategoryRow();

            if (string.IsNullOrEmpty(DepCat_NameEn)) DepRow.SetDepCat_NameEnNull(); else DepRow.DepCat_NameEn = DepCat_NameEn;
            if (string.IsNullOrEmpty(DepCat_MangerPhone)) DepRow.SetDepCat_MangerPhoneNull(); else DepRow.DepCat_MangerPhone = DepCat_MangerPhone;
            if (string.IsNullOrEmpty(DepCat_MangerInternalPhone)) DepRow.SetDepCat_MangerInternalPhoneNull(); else DepRow.DepCat_MangerInternalPhone = DepCat_MangerInternalPhone;
            if (string.IsNullOrEmpty(DepCat_Phone)) DepRow.SetDepCat_PhoneNull(); else DepRow.DepCat_Phone = DepCat_Phone;
            if (string.IsNullOrEmpty(DepCat_InternalPhone)) DepRow.SetDepCat_InternalPhoneNull(); else DepRow.DepCat_InternalPhone = DepCat_InternalPhone;
            if (string.IsNullOrEmpty(DepCat_Email)) DepRow.SetDepCat_EmailNull(); else DepRow.DepCat_Email = DepCat_Email;

            if (DepCat_DeptID == null) DepRow.SetDepCat_DeptIDNull(); else DepRow.DepCat_DeptID = DepCat_DeptID.Value;
            if (DepCat_SubDeptID == null) DepRow.SetDepCat_SubDeptIDNull(); else DepRow.DepCat_SubDeptID = DepCat_SubDeptID.Value;
            if (DepCat_DeptCategID == null) DepRow.SetDepCat_DeptCategIDNull(); else DepRow.DepCat_DeptCategID = DepCat_DeptCategID.Value;

            DepRow.DepCat_NameAr = DepCat_NameAr;
            DepTable.AddDepCategoryRow(DepRow);

            int rowsAffected = DepCategoryTableAdapter.Update(DepTable);
            return rowsAffected == 1;
        }

        #endregion

        #region updateEcsOffice
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]

        public bool UpdateDepartment
          (string DepCat_NameAr, string DepCat_NameEn, int? DepCat_DeptCategID, int? DepCat_DeptID, int? DepCat_SubDeptID,
          string DepCat_MangerPhone, string DepCat_MangerInternalPhone, string DepCat_Phone, string DepCat_InternalPhone,
          string DepCat_Email, int DepCat_id)
        {
            EcsSiteDS.DepCategoryDataTable DepTable =
                DepCategoryTableAdapter.GetDepCategoryDataByDepCatID(DepCat_id);

            if (DepTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.DepCategoryRow DepRow = DepTable[0];

            if (string.IsNullOrEmpty(DepCat_NameEn)) DepRow.SetDepCat_NameEnNull(); else DepRow.DepCat_NameEn = DepCat_NameEn;
            if (string.IsNullOrEmpty(DepCat_MangerPhone)) DepRow.SetDepCat_MangerPhoneNull(); else DepRow.DepCat_MangerPhone = DepCat_MangerPhone;
            if (string.IsNullOrEmpty(DepCat_MangerInternalPhone)) DepRow.SetDepCat_MangerInternalPhoneNull(); else DepRow.DepCat_MangerInternalPhone = DepCat_MangerInternalPhone;
            if (string.IsNullOrEmpty(DepCat_Phone)) DepRow.SetDepCat_PhoneNull(); else DepRow.DepCat_Phone = DepCat_Phone;
            if (string.IsNullOrEmpty(DepCat_InternalPhone)) DepRow.SetDepCat_InternalPhoneNull(); else DepRow.DepCat_InternalPhone = DepCat_InternalPhone;
            if (string.IsNullOrEmpty(DepCat_Email)) DepRow.SetDepCat_EmailNull(); else DepRow.DepCat_Email = DepCat_Email;

            if (DepCat_DeptID == null) DepRow.SetDepCat_DeptIDNull(); else DepRow.DepCat_DeptID = DepCat_DeptID.Value;
            if (DepCat_SubDeptID == null) DepRow.SetDepCat_SubDeptIDNull(); else DepRow.DepCat_SubDeptID = DepCat_SubDeptID.Value;
            if (DepCat_DeptCategID == null) DepRow.SetDepCat_DeptCategIDNull(); else DepRow.DepCat_DeptCategID = DepCat_DeptCategID.Value;

            DepRow.DepCat_NameAr = DepCat_NameAr;

            int rowsAffected = DepCategoryTableAdapter.Update(DepTable);
            return rowsAffected == 1;
        }
        #endregion


        #region DeleteEcsOffice
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteDep(int DepCat_id)
        {
            int rowsAffected = DepCategoryTableAdapter.Delete(DepCat_id);
            return rowsAffected == 1;
        }

        #endregion

    }
}